﻿using System;
using XRM.Security.DataAccess;
using XRM.Security.WebUI.Consts;

namespace XRM.Security.WebUI.Models.Report.ReportBuilder
{
    public static class ReportBuilderFactory
    {
        public static string CreateReport(CreateReportModel model, IDataManager dataManager)
        {
            return GetBuilder( model.ReportType, dataManager ).Create( model );
        }

        public static IReportBuilder GetBuilder(ReportTypes reportType, IDataManager dataManager)
        {
            switch (reportType)
            {
                case ReportTypes.UserReport:
                    return new UserReportBuilder(dataManager.UserRegisterRepository);
                case ReportTypes.ExpireCertReport:
                    return new ExpireCertReportBuilder( dataManager.CertRegisterRepository );
                case ReportTypes.CertReport:
                    return new CertReportBuilder( dataManager.CertRegisterRepository );
                case ReportTypes.DepartmentByScsiReport:
                    return new DepartmentByScsiReportBuilder( dataManager.UserSkziRepository );
                case ReportTypes.OpenRequestReport:
                    return new OpenRequestReportBuilder( dataManager.RequestRepository );
                case ReportTypes.RequestByWorkKindReport:
                    return new RequestByWorkKindReportBuilder( dataManager );
                case ReportTypes.ScsiReport:
                    return new ScsiReportBuilder( dataManager );
            }
            throw new NotSupportedException("Неподдерживаемый тип отчетов");
        }
    }

    public interface IReportBuilder
    {
        string Create( CreateReportModel model );
    }
}